<?php
// No direct access to this file
defined('_JEXEC') or die;
 
// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
 
/**
 * HelloWorld Form Field class for the HelloWorld component
 */
class JFormFieldCategory extends JFormFieldList
{
	/**
	 * The field type.
	 *
	 * @var		string
	 */
	protected $type = 'Category';
 
	/**
	 * Method to get a list of options for a list input.
	 *
	 * @return	array		An array of JHtml options.
	 */
	protected function getOptions() 
	{
	
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
 		$query->select("t2.id as value,t2.title as text ,t2.level");
		$query->from("#__shop_category t1,#__shop_category t2");
		$query->where('t2.lft BETWEEN t1.lft AND t1.rgt');
		$query->group('t2.id,t2.lft,t2.rgt,t2.title');
		$query->order("t2.lft asc");

		// Get the options.
		$db->setQuery($query);
		
		$listcat = $db->loadObjectList();
		
		$options = array();
		if ($listcat)
		{
			foreach($listcat as $row) 
			{
				$options[] = JHtml::_('select.option', $row->value, str_repeat('-- ',$row->level).$row->text);
			}
		}
		$options = array_merge(parent::getOptions(), $options);
		return $options;
	}
}